package com.benz.order.util;

import java.util.Random;

public class TestUtil {
    public static void main(String[] args) {
        char a = 'a';
        char b = 97;
        byte c = 127;
        char d = 127;
        short s = 1;
        char  e = 101;
        int f = s;
        int g = e;

        byte b1;
        int  b2=298;
        int  b3=393;
        b1 = (byte)b3;
        byte b4=3;
        byte b6=3;
        byte b7=5;
        byte b5 = (byte)(b6 + b7);
        System.out.println("b1:"+b1);
        System.out.println("b5:"+b5);


        int a1=3;
        int a2=4;

        int a3=a1+a2++;

        System.out.println("a2:"+a2);
        System.out.println("a3:"+a3);

        int a4=3500/1000*100;

        System.out.println("a4:"+a4);
        System.out.println("a5:"+35000/1000*1000);

        System.out.println("a6:"+(-5%3));
        System.out.println("a6:"+(5%(-3)));


        short s1 = 3;
        int i1 = 5;

        s1+=i1;
        s1 = (short)(s1+i1);

        System.out.println("s1:"+s1);

        System.out.println("======================");

        int x=1;

        while(x<=4){
            System.out.println("x:"+x);
            if(x == 3){
                break;
            }
            x++;
        }

        int i,j;
        itcast:for(i=1;i<=4;i++){
            for(j=1;j<=i;j++){
                if(i>3){
                    break itcast;
                }
                System.out.print("*");
            }
            System.out.println("\n");
        }
        //数组
        int[] arr = new int[50];
        int[] arr2;
        arr2 = new int[3];
        System.out.println(arr2[0]);
        System.out.println(arr2[1]);
        System.out.println(arr2[2]);

        int[] arr3 = new int[]{1,2,3};
        int[] arr4 =  {1,2,3,5,0};

        System.out.println(arr3[0]);
        System.out.println(arr4[0]);

        int max = getMax(arr4);
        System.out.println("max:"+max);
        System.out.println("=======================");
        System.out.println("=========排序前=========");
        printArray(arr4);
        bubbleSort(arr4);
        System.out.println("=========排序后=========");
        printArray(arr4);

        String[] students = new String[]{"a","b","c","d","e"};
        int rand =  randomStudentName(students);
        System.out.println("<UNK>:"+rand);
    }
    static int getMax(int[] arr){

        int max = arr[0];
        for(int i=1;i<arr.length;i++){
            if(arr[i] > max){
                max = arr[i];
            }
        }
        return max;
    }
    static void printArray(int[] arr){
        for (int j : arr) {
            System.out.print(j+" ");
        }
        System.out.println("\n");
    }
    static void bubbleSort(int[] arr){
        for (int i = 1; i < arr.length; i++) {
            for (int j = 0; j < arr.length - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
            System.out.println("第" + (i+1) + "轮排序后:");
            printArray(arr);
        }
        //return arr;
    }
    static int randomStudentName(String[] students){
        int idx = new Random().nextInt(10);
        System.out.println(idx);
        return idx;
    }
}






